require "Common/define"
require "Logic/Config"

UIPrivacy = UIBase.New(PanelResNames.UIPrivacy)
local this = UIPrivacy
local agreementType = 0;--1用户协议 2隐私政策 3账号注销
local decName  = {
    "useragreement",
    "privacypolicy",
    "cancellationagreement"
}
function UIPrivacy.Init(type)
    agreementType = type
    UIBase.Init(this)
end

function UIPrivacy:OnCreate()
    self.Btn_BgClose = self:GetChild("Btn_BgClose")
    self.btnClose = self:GetChild("Btn_Confirm")
    self.decText = self:GetChild("n5"):GetChild("title")
    self.scrollPane=self:GetChild("n5").scrollPane; 
    self.titleText = self:GetChild("Com_ThreeBg"):GetChild("title")


    --self:InitView()
    self:BindEvent()
end

function UIPrivacy:InitView()
    local titleName;
    if agreementType == 2 then
        titleName = "Agreement_Tips1";
    elseif agreementType == 1 then
        titleName = "Agreement_Tips2";
    else
        titleName = "Agreement_Tips3";
    end
        self.titleText.text = getLanguage(titleName)
        local platform = "android"
        if Application.platform == RuntimePlatform.IPhonePlayer then
            platform = "ios"
        end
        local url ="http://fsgame.xiaoniuhy.com/useragreement/"..platform.."/"..Config.SDK_Channel .."/"..decName[agreementType] ..".txt"
        Http.Get(url, nil, function(success, str)
            if not success then
                logError("http get fight cmd failed. url: " .. url .. ". ErrMsg: " .. str)
                return
            end
            if self.decText == nil then return end
            self.decText.text = str;
        end)
        self.scrollPane.posY=0;
    end
function UIPrivacy:OnEnable()
    self:InitView()
end
function UIPrivacy:OnDisable()

end

function UIPrivacy:OnClose()
    closeUI(PanelResNames.UIPrivacy)
end

function UIPrivacy:BindEvent()
    self:RegisterOnClick(self.btnClose, self.OnClose)
    self:RegisterOnClick(self.Btn_BgClose, self.OnClose)

end


return UIPrivacy;